@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="card-title mb-0">操作日志</h5>
                    <a href="{{ route('logs.export') }}" class="btn btn-info btn-sm">
                        <i class="bi bi-download"></i> 导出
                    </a>
                </div>
                <div class="card-body">
                    <form action="{{ route('logs.index') }}" method="GET" class="mb-4">
                        <div class="row g-3">
                            <div class="col-md-3">
                                <label for="user_id" class="form-label">用户</label>
                                <select name="user_id" id="user_id" class="form-select">
                                    <option value="">全部用户</option>
                                    @foreach($users as $user)
                                        <option value="{{ $user->id }}" 
                                            {{ request('user_id') == $user->id ? 'selected' : '' }}>
                                            {{ $user->username }}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="col-md-3">
                                <label for="action" class="form-label">操作类型</label>
                                <select name="action" id="action" class="form-select">
                                    <option value="">全部操作</option>
                                    @foreach($actions as $action)
                                        <option value="{{ $action }}" 
                                            {{ request('action') == $action ? 'selected' : '' }}>
                                            {{ $action }}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="col-md-3">
                                <label for="target_type" class="form-label">目标类型</label>
                                <select name="target_type" id="target_type" class="form-select">
                                    <option value="">全部类型</option>
                                    @foreach($targetTypes as $type)
                                        <option value="{{ $type }}" 
                                            {{ request('target_type') == $type ? 'selected' : '' }}>
                                            {{ $type }}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="col-md-3">
                                <label for="date_start" class="form-label">开始日期</label>
                                <input type="date" class="form-control" id="date_start" name="date_start" 
                                    value="{{ request('date_start') }}">
                            </div>
                            <div class="col-md-3">
                                <label for="date_end" class="form-label">结束日期</label>
                                <input type="date" class="form-control" id="date_end" name="date_end" 
                                    value="{{ request('date_end') }}">
                            </div>
                            <div class="col-md-3 d-flex align-items-end">
                                <button type="submit" class="btn btn-primary me-2">搜索</button>
                                <a href="{{ route('logs.index') }}" class="btn btn-secondary">重置</a>
                            </div>
                        </div>
                    </form>

                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead class="table-light">
                                <tr>
                                    <th>ID</th>
                                    <th>用户</th>
                                    <th>操作类型</th>
                                    <th>目标类型</th>
                                    <th>目标ID</th>
                                    <th>操作内容</th>
                                    <th>IP地址</th>
                                    <th>时间</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($logs as $log)
                                    <tr class="{{ $loop->even ? 'table-light' : '' }}">
                                        <td>{{ $log->id }}</td>
                                        <td>{{ $log->user ? $log->user->username : '已删除用户' }}</td>
                                        <td>{{ $log->action }}</td>
                                        <td>{{ $log->target_type }}</td>
                                        <td>{{ $log->target_id }}</td>
                                        <td>{{ $log->content }}</td>
                                        <td>{{ $log->ip }}</td>
                                        <td>{{ $log->created_at->format('Y-m-d H:i:s') }}</td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>

                    <div class="d-flex justify-content-center mt-4">
                        {{ $logs->links() }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection 